package com.wuxb.masterWorker;

import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentSkipListSet;

public abstract class Worker<T> implements Runnable{

    private ConcurrentLinkedQueue<T> queue = new ConcurrentLinkedQueue();

    private ConcurrentSkipListSet<Object> resultMap = new ConcurrentSkipListSet<Object>();

    @Override
    public void run() {
        while (true){
            T task = queue.poll();
            if (task==null)break;
            Object result = handle(task);
            //resultMap.put(task.getId()+"",result);
            resultMap.add(result);
        }
    }

    public abstract Object handle(T task);


    public void setQueue(ConcurrentLinkedQueue<T> queue) {
        this.queue = queue;
    }

    public ConcurrentSkipListSet<Object> getResultMap() {
        return resultMap;
    }

    public void setResultMap(ConcurrentSkipListSet<Object> resultMap) {
        this.resultMap = resultMap;
    }

    public ConcurrentLinkedQueue<T> getQueue() {
        return queue;
    }
}
